<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"   %>
<%@ include file="/common/taglibs.jsp" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/common/res-select2.jsp" %>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <form  method="post" id="inputForm" name="inputForm" class="form-horizontal" style="padding:5px 20px 0 0"  role="form">
            <form:hidden path="entity.id" />
            <div class="form-group">
                <label class="col-md-2 col-xs-2 control-label" for="name">姓名<i  class="red">*</i></label>
                <div class="col-md-10 col-xs-10"  >
                    <input class="form-control"  name="name"    id="name"  type="text"  value="${entity.name}" placeholder="输入姓名">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 col-xs-2 control-label" for="loginName">登录名<i  class="red">*</i></label>
                <div class="col-md-10 col-xs-10"  >
                    <input class="form-control"  name="loginName"    id="loginName"  type="text"  value="${entity.loginName}" placeholder="输入登录名">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 col-xs-2 control-label" for="plainPassword">新密码</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="plainPassword"    id="plainPassword"  type="password"
                           value="${entity.plainPassword}" placeholder="输入新密码">
                </div>
                <label class="col-md-2 col-xs-2 control-label" for="plainPassword2">确认新密码</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="plainPassword2"    id="plainPassword2"  type="password"
                            placeholder="输入新密码">
                </div>
            </div>
            <div class="form-group">

                <label class="col-md-2 col-xs-2 control-label" for="mobile">手机号码</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="mobile"    id="mobile"  type="text"
                           value="${entity.mobile}"    placeholder="输入手机号码">
                </div>

                <label class="col-md-2 col-xs-2 control-label" for="email">电子邮箱</label>
                <div class="col-md-4 col-xs-4"  >
                    <input class="form-control"  name="email"    id="email"  type="text"
                           value="${entity.email}" placeholder="输入电子邮箱">
                </div>
            </div>
            <div class="form-group">

                <label class="col-md-2 col-xs-2 control-label" for="mobile">菜单权限<i  class="red">*</i></label>
                <div class="col-md-10 col-xs-10"  >
                    <input class="form-control" type="text" id="permissions" name="permissions" value="${entity.permissions}" multiple >
                </div>

            </div>
        </form>

    </div>
    <!--/.col-md-12-->
</div>
<!--/.row-->
<script>
    $(function () {
        var $inputForm = $('#inputForm');

        /////////////select2////////////
        $inputForm.find('#permissions').select2({
            width:'100%',
            placeholder: "选择权限",
            data:${menuPerSelect2JsonArr},
//            allowClear: true,
            tags: true,
            tokenSeparators: [',', ' ']
        });
        //ajax提交表单配置.
        var ajaxSubmitOption = {
            beforeSubmit: function () {
                //mask form,防止多次提交
                $inputForm.block()
            },
            success: function (resp, statusText) {
                $inputForm.unblock()
                window.refreshParentDataGrid();
                bootbox.hideAll();
                P.messager({content:resp.msg,type:resp.success==true?'success':'error'}) ;
            },
            url: P.ctx +  '/op/user/input?',
            type: 'post',
            dataType: 'json'
        };
        //jquery validate 验证表单
        $inputForm.validate({
            submitHandler: function (form) {
                //验证成功之后使用jquery form提交表单.
                $(form).ajaxSubmit(ajaxSubmitOption);
            },
            rules: {
                permissions: {
                    required: true
                },
                name: {
                    required: true,
                    normalChar: true,
                    maxlength: 50
                },
                loginName: {
                    required: true,
                    maxlength: 50,
                    account: true,
                    remote: {
                        url:P.ctx +  '/op/user/validateLoginName', //后台处理程序
                        type: 'post',               //数据发送方式
                        dataType: 'json',           //接受数据格式
                        data: {                     //要传递的数据
                            userId: function () {
                                return $inputForm.find('#id').val();
                            }
                        }
                    }
                },
                email: {
                    required: false,
                    email: true,
                    remote: {
                        url:P.ctx +  '/op/user/validateEmail', //后台处理程序
                        type: 'post',               //数据发送方式
                        dataType: 'json',           //接受数据格式
                        data: {                     //要传递的数据
                            userId: function () {
                                return $inputForm.find('#id').val();
                            }
                        }
                    }
                },
                mobile: {
                    required: false,
                    isMobile: true,
                    remote: {
                        url: P.ctx + '/op/user/validateMobile', //后台处理程序
                        type: 'post',               //数据发送方式
                        dataType: 'json',           //接受数据格式
                        data: {                     //要传递的数据
                            userId: function () {
                                return $inputForm.find('#id').val();
                            }
                        }
                    }
                },
                plainPassword: {
                    minlength: 6,
                    maxlength: 32,
                    equalTo:'#plainPassword2'
                },
                plainPassword2: {
                    minlength: 6,
                    maxlength: 32
                },
                sortNum: {
                    digits: true
                }
            }, messages: {  //自定义提示消息.
                loginName: {
                    remote: '该用户名已存在'
                },
                email: {
                    remote: '该Email已存在'
                },
                plainPassword: {
                    minlength: '密码之后六位字符'
                }
            }
        }); //end validate

    });//Dom ready
</script>
</body>
</html>